package com.hit.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hit.commonUtils.R;
import com.hit.eduService.entity.EduCourse;
import com.hit.eduService.entity.EduTeacher;
import com.hit.eduService.service.EduCourseService;
import com.hit.eduService.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("eduService/indexFront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;
    @Autowired
    private EduTeacherService eduTeacherService;
    //查询前8条热门课程，前4条名师
    @GetMapping("getCourseAndTeacherWithCondition")
    public R getCourseAndTeacher(){
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("view_count");
        wrapper.last("limit 8");
        List<EduCourse> eduCourses = eduCourseService.list(wrapper);

        QueryWrapper<EduTeacher> wrapperTeacher=new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<EduTeacher> eduTeachers = eduTeacherService.list(wrapperTeacher);

        return R.ok().data("eduCourses",eduCourses).data("eduTeachers",eduTeachers);

    }
}
